<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<#include "/views/ftl/base/manager_include.ftl">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>进货单</title>
<style>
A{
color: #333;
}

.btnjia {
    float: left;
    border: 1px solid #d6d6d6;
    height: 22px;
    width: 24px;
    text-align: center;
    display: inline-block;
    font-size: 18px;
    line-height: 22px;
    font-weight: bold;
    color: #aaa;
}
.jjBox {
    float: left;
    height: 14px;
    width: 34px;
    padding: 4px 0;
    border: none;
    text-align: center;
    border-bottom: 1px solid #d6d6d6;
    border-top: 1px solid #d6d6d6;
    display: inline-block;
    outline: none;
    color: #666;
    overflow: hidden;
}
</style>
<script type="text/javascript">
$(function(){
	$("#search_button").click(function(){
		$('#select_form').submit();
    });
});

</script>
</head>
<body style="background:#eef3f7;">
<#include "/views/ftl/base/head.ftl">
<div class="Main">
  <div class="dw">
<#include "/views/ftl/base/menu.ftl">
<#function a><#return "进货单_List"></#function> 
<!--右边内容-->
<div class="Rightbox fl">
    <!--导航-->
    <div class="Bread_crbs clear">
      <div class="Bread_crbs_img fl"></div>
      <div class="Bread_crbs_text fl">
      	<a href="javascript:void(0);"><span>商品管理</span></a>
      	<span class="fnt_famy">></span>
      	<a href="javascript:void(0);"><span>货品列表</span></a>
      </div>
    </div>
    	
      <!--搜索框-->
        <#--<form action="${basePath}manager/Goods_goodsListPage" id="select_form"  method="GET"> 
        	<div style="display:none;">
         	<div class="searchBox fl"> 
         		<span class=" searchTitle">条形码:</span> 
          		<input class="search_text" type="text" name="brandName" placeholder="请输入关键字 " value="${(requestVo.brandName)!''}"/>  
         	</div>
         	 <a href="javascript:void(0);" id="search_button"   class="search_btn fl" align="center"><span >搜索</span></a> 
        	</div>
        	<div  >
         	<div class="searchBox fl"> 
         		<span class=" searchTitle">条形码:</span> 
          		<input class="search_text" type="text" name="brandName" placeholder="请输入关键字 " value="${(requestVo.brandName)!''}"/>  
         	</div>
         	 <a href="javascript:void(0);" id="search_button"   class="search_btn fl" align="center"><span >搜索</span></a> 
        	</div>
        	
        	
			<a href="${basePath}manager/Goods_createGoodsPage" class="search_btn fl" style="width:89px;background: #00ad55 none repeat scroll 0 0;" target="_blank"><span>添加货品</span></a>
        </form>-->
        <div> 
        	
        	<div id="no_div_1" >
	         	<div class="searchBox fl"> 
	         		<span class=" searchTitle">条形码:</span> 
	          		<input class="search_text" type="text" name="barCode" placeholder="请输入关键字 " value=""/>  
	         	</div>
	         	<a href="javascript:void(0);" id="no_div_btn_1"   class="search_btn fl" align="center"><span >搜索</span></a>
        	</div>
        	
        	<div id="no_div_2" style="display:none;">
	         	<div class="searchBox fl"> 
	         		<span class=" searchTitle">货品号:</span> 
	          		<input class="search_text" type="text" name="goodsNumber" placeholder="请输入关键字 " value=""/>
	          		
	          		<span class=" searchTitle">颜色:</span> 
	          		<select name="goodsCategoryParentId" style="width: 100px; vertical-align: middle;"  class="sp">
		           	<option value=""  >----</option>
					</select>
					<span class=" searchTitle">尺码:</span>
	          		<select name="goodsCategoryParentId" style="width: 100px; vertical-align: middle;"  class="sp">
		           	<option value=""  >----</option>
					</select>
	         	</div>
	         	<a href="javascript:void(0);" id="no_div_btn_2"   class="search_btn fl" align="center"><span >添加</span></a>
        	</div> 
        	
			<a href="javascript:void(0);" id="change_no_div" data-no-div='1' class="search_btn fl" style="width:89px;background: #00ad55 none repeat scroll 0 0;" target="_blank"><span>切换</span></a>
        </div>

        
       <!-- brandId,goodsNumber,goodsName,goodsCategoryId,totalStockCount,applySex,tagPrice,retailPrice,season,unit,-->
        <div class="clear"></div>
        <!--表格列表-->
        
        <div class="Table">
          <table id="table" cellpadding="0" cellspacing="1">
            <tbody id="purchase_product_list">
             <tr id="gl"> 
             <td>条码</td>
             <td>货品号</td>
             <td>货品名</td>
             <td>颜色</td>
             <td>尺码</td>
             <td>库存</td>  
             <td>零售价</td> 
             <td style="width:90px;">数量</td>
             <td>操作</td>
             </tr> 
              
            <#--<#if (pager.list??)> 
           <#if ((pager.list?size)>0)>
           <#list pager.list as product>
     		<tr>  
     		  <td>${(product.barCode)!''}</td>
              <td>${(product.goodsNumber)!''}</td> 
               <td>${(product.goodsName)!''}</td> 
               <td>${(product.colorSpecificationValue)!''}</td>
             <td>${(product.sizeSpecificationValue)!''}</td>
             <td>${(product.stockCount)?c}</td>   
                <td>${(product.retailPrice)?c}</td>  
           	<td class="tbl_btn">
                <a href="${basePath}manager/Goods_goodsInfo?goodsId=${(product.goodsId)?c}"><span class="review_single_model" style="    background: #00ad55;">查看</span></a>
                 
                </td>
              </tr>
  			</#list>
          </#if>
          </#if>-->
            </tbody>
          </table>
        </div>
        
        
       <#-- <div class="Table">
          <table id="table" cellpadding="0" cellspacing="1">
            <tbody>
              <tr id="gl"> 
              <td>条码</td>
             <td>货品号</td>
             <td>货品名</td>
             <td>颜色</td>
             <td>尺码</td>
             <td>库存</td>  
             <td>零售价</td>  
             <td>操作</td>
             </tr>
            <#if (pager.list??)> 
           <#if ((pager.list?size)>0)>
           <#list pager.list as product>
     		<tr>  
     		  <td>${(product.barCode)!''}</td>
              <td>${(product.goodsNumber)!''}</td> 
               <td>${(product.goodsName)!''}</td> 
               <td>${(product.colorSpecificationValue)!''}</td>
             <td>${(product.sizeSpecificationValue)!''}</td>
             <td>${(product.stockCount)?c}</td>   
                <td>${(product.retailPrice)?c}</td>  
           	<td class="tbl_btn">
                <a href="${basePath}manager/Goods_goodsInfo?goodsId=${(product.goodsId)?c}"><span class="review_single_model" style="    background: #00ad55;">查看</span></a>
                 
                </td>
              </tr>
  			</#list>
          </#if>
          </#if>
            </tbody>
          </table>
        </div>-->
        
    <!--翻页按钮-->
  	<#--<#import "../../base/pager.ftl" as p>
   	<@p.pager pager = pager baseUrl = "manager/Product_productListPage" parameterMap={"brandName":(brandName)!''} /> -->
   	<div style="float: right;margin-right: 10px;">
   		<span >总数量:</span><span style="margin-left: 30px;font-size: 18px;color: #FF4200;" id="pro_total_count">0</span><span >件</span>
   		<input id="create_purchase_sale_order_btn" style="margin-left: 30px;width: 50px;" type="button" value="提交" class="page_botn">
   	</div>
   	
</div>
<script type="text/javascript">
$(function(){
	//切换
	$('#change_no_div').click(function(){
		var div_no = $(this).attr('data-no-div');
		if('1'==div_no){
			$(this).attr('data-no-div','2');
			$('#no_div_1').hide();
			$('#no_div_2').show(); 
		}
		if('2'==div_no){
			$(this).attr('data-no-div','1');
			$('#no_div_2').hide();
			$('#no_div_1').show(); 
		} 
	
	});
	
	$('#no_div_btn_1').click(function(){
		var barCode = $('input[name="barCode"]').val();
		productByBarCode(barCode);
		
	});
	
	function productByBarCode(barCode){
		$.ajax({ 
			url : "${basePath}manager/Product_productByBarCode",
			data : {
				barCode:barCode
			}, 
			dataType :"JSON",
			cache : false, 
			type : "POST",
			success : function(dat){
				if(dat.code==1){
					 var alhtm ='货品号:'+dat.data.goodsNumber+'\n';
					 alhtm+='货品名:'+dat.data.goodsName+'\n';
					 alhtm+='条形码:'+dat.data.barCode+'\n';
					 alhtm+='颜色:'+dat.data.colorSpecificationValue+'\n';
					 alhtm+='尺码:'+dat.data.sizeSpecificationValue+'\n';
					 alhtm+='价格:'+dat.data.retailPrice+'\n';
					 
					 var buyCount=prompt(alhtm,"");
					 if(!/^(\+|-)?(\d+)(\.\d*)?$/g.test(buyCount)){
						return false;
					 }
					 addProduct(dat.data.productId,buyCount);
				} 
			}
		});
	}
	
	function addProduct(productId, quantity){
		$.ajax({ 
			url : "${basePath}manager/PurchaseSaleOrder_addProduct",
			data : {
				productId:productId,
				quantity:quantity
			}, 
			dataType :"JSON",
			cache : false, 
			type : "POST",
			success : function(dat){
				if(dat.code==1){
					 alert("添加成功");
					 loadProductInBuyCar();
				}else{
					alert(dat.msg);
				}
			}
		}); 
	}
	
	function modifyProduct(productId, quantity){
		if(quantity<=0){
			return false;
		}
		var result =false;
		$.ajax({ 
			url : "${basePath}manager/PurchaseSaleOrder_modifyProduct",
			data : {
				productId:productId,
				quantity:quantity
			}, 
			dataType :"JSON",
			cache : false, 
			type : "POST",
			async: false,
			success : function(dat){
				if(dat.code==1){
					result=true;
				}else{
					alert(dat.msg);
				}
			}
		});
		return result;
	}
	
	function removeProduct(productId){
		$.ajax({ 
			url : "${basePath}manager/PurchaseSaleOrder_removeProduct",
			data : {
				productId:productId
			}, 
			dataType :"JSON",
			cache : false, 
			type : "POST",
			async: false,
			success : function(dat){
				if(dat.code==1){
					 alert("成功");
					 loadProductInBuyCar();
				}else{
					alert(dat.msg);
				}
			}
		}); 
	}
	
	
	
	
	loadProductInBuyCar();
	function loadProductInBuyCar(){
		$.ajax({ 
			url : "${basePath}manager/PurchaseSaleOrder_productInBuyCar",
			data : {
				
			}, 
			dataType :"JSON",
			cache : false, 
			type : "POST",
			success : function(dat){
				if(dat.code==1){
					$('.product_tr').remove();
					var html='';
					$(dat.data).each(function(index,bean){
						html+='<tr class="product_tr"> ';
						html+='<td>'+bean.barCode+'</td>';
						html+='<td>'+bean.goodsNumber+'</td> ';
						html+=' <td>'+bean.goodsName+'</td> ';
						html+='<td>'+bean.colorSpecificationValue+'</td>';
						html+=' <td>'+bean.sizeSpecificationValue+'</td>';
						html+='<td>'+bean.stockCount+'</td>   ';
						html+='<td>'+bean.retailPrice+'</td>  ';
						html+='  <td><div class="number" >';
						html+=' <a class="btnjia minPro_One" data-id="'+bean.productId+'" href="javascript:void(0);">-</a>';
						html+='<input class="jjBox" id="pro_id_'+bean.productId+'" value="'+bean.quantity+'" data-max="0" data-now="'+bean.quantity+'" name="" type="text">';
						html+=' <a class="btnjia addPro_One" data-id="'+bean.productId+'"  href="javascript:void(0);">+</a> ';
						html+='  </div></td>  ';
						html+='<td class="tbl_btn">';
						html+='  <a href="${basePath}manager/Goods_goodsInfo?goodsId='+bean.goodsId+'"><span class="review_single_model" style="    background: #00ad55;">查看</span></a>';
						html+=' <a href="javascript:void(0);" class="remove_product_btn" data-id="'+bean.productId+'"><span class="review_single_model" style="    background: #FF0202;">删除</span></a>';
						html+=' </td>';
						html+=' </tr>';
					});
					$('#purchase_product_list').append(html);
					
					//移除
					$('.remove_product_btn').unbind("click").click(function(){
						removeProduct($(this).attr('data-id'));
					});
					
					
					$('.minPro_One').unbind("click").click(function(){
						var productId = $(this).attr("data-id");
						var quantity  = $('#pro_id_'+productId).val();
						quantity = parseInt(quantity)-1;
						
						if(modifyProduct(productId,quantity)){
							$('#pro_id_'+productId).val(quantity);
							calcTotal();
						}
						
					});
					
					$('.addPro_One').unbind("click").click(function(){
						var productId =$(this).attr("data-id");
						var quantity =$('#pro_id_'+productId).val();
						
						quantity =parseInt(quantity)+1; 
						if(modifyProduct(productId,quantity)){
							$('#pro_id_'+productId).val(quantity);
							calcTotal();
						}
					});
					
					
					calcTotal();
				}else if(dat.code==-1){
					$('.product_tr').remove();
				
				}else{
					alert(dat.msg);
				}
			}
		}); 
	}
	
	function calcTotal(){
		var $jjBox =$('.jjBox');
		var total =0;
		$($jjBox).each(function(index,bean){ 
			total+= parseInt($(bean).val()); 
		});
		$('#pro_total_count').html(total); 
	}
	
	$('#create_purchase_sale_order_btn').click(function(){
	createPurchaseSaleOrder();
	
	});
	
	
	function createPurchaseSaleOrder(){
		$.ajax({ 
			url : "${basePath}manager/PurchaseSaleOrder_createPurchaseSaleOrder",
			data : {
				
			}, 
			dataType :"JSON",
			cache : false, 
			type : "POST",
			async: false,
			success : function(dat){
				if(dat.code==1){
					 
					 alert("成功"); 
				}else{ 
					alert(dat.msg);
					window.location.reload();
				}
			}
		}); 
	}
	

	
	
});
</script>
</body>
</html>

